import { createStore } from 'vuex'
// import {BodyScroll} from '@/utils/utils'

let timeout1 = null
let timeout2 = null

let mutations = {
  controlMask (state, payload) {
    if (timeout1) {
      clearTimeout(timeout1)
    }
    timeout1 = setTimeout(() => {
      state.maskState = payload.maskState
    }, 100)
  },
  controlLoading (state, payload) {
    if (timeout2) {
      clearTimeout(timeout2)
    }
    timeout2 = setTimeout(() => {
      state.isLoading = payload.isLoading
    }, 100)
  },
  saveRequestParams (state, payload) {
    state.unionKey = payload.unionKey
    state.token = payload.token
  },
  titleConfig (state, payload) {
    state.title = payload.title
    state.isAlways = payload.isAlways
  }
}

let actions = {
  showLoading ({ commit }, data) {
    commit('controlLoading', {
      isLoading: data.isLoading
    })
    commit('controlMask', {
      maskState: data.isLoading
    })
  }
}

export default createStore({
  state: {
    maskState: false,
    unionKey: '',
    token: '',
    isLoading: false,
    title: '',
    isAlways: false
  },
  mutations: mutations,
  actions: actions,
  modules: {
  }
})
